home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / WriteStream.st < prev    next >
Text File  |  1991-09-12  |  3KB  |  153 lines

  1. "======================================================================
  2. |
  3. |   WriteStream Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     20 May 90      Fixed semantics of write streams so that they return
  34. |                         only the characters that have been written to them.
  35. |
  36. | sbyrne     19 Sep 89      Changed to use real method categories.
  37. |
  38. | sbyrne     25 Apr 89      created.
  39. |
  40. "
  41.  
  42. PositionableStream subclass: #WriteStream
  43.            instanceVariableNames: 'maxSize'
  44.            classVariableNames: ''
  45.            poolDictionaries: ''
  46.            category: nil.
  47.  
  48. WriteStream comment: 
  49. 'I am the class of writeable streams.  I only allow write operations to
  50. my instances; reading is strictly forbidden.' !
  51.  
  52. !WriteStream class methodsFor: 'instance creation'!
  53.  
  54. on: aCollection
  55.     ^(self new initCollection: aCollection) access: 2
  56. !
  57.  
  58. with: aCollection
  59.     | stream |
  60.     stream _ self on: aCollection.
  61.     stream moveToEnd.
  62.     ^stream
  63. !
  64.  
  65. with: aCollection from: firstIndex to: lastIndex
  66.     | stream |
  67.     stream _ self on: aCollection fromFirstIndex to: lastIndex.
  68.     stream moveToEnd.
  69.     ^stream
  70. !!
  71.  
  72.  
  73.  
  74. !WriteStream methodsFor: 'accessing-writing'!
  75.  
  76. nextPut: anObject
  77.     (access bitAnd: 2) = 0
  78.        ifTrue: [ ^self shouldNotImplement ].
  79.     ptr > maxSize ifTrue: [ self growCollection ].
  80.     collection at: ptr put: anObject.
  81.     ptr > endPtr ifTrue: [ endPtr _ ptr ].
  82.     ptr _ ptr + 1.
  83.     ^anObject
  84. !!
  85.  
  86.  
  87.  
  88. !WriteStream methodsFor: 'positioning'!
  89.  
  90. setToEnd
  91.     ptr _ endPtr + 1
  92. !!
  93.  
  94.  
  95.  
  96. !WriteStream methodsFor: 'character writing'!
  97.  
  98. cr
  99.     self nextPut: Character cr
  100. !
  101.  
  102. nl
  103.     self nextPut: Character nl
  104. !
  105.  
  106. crTab
  107.     self cr.
  108.     self tab
  109. !
  110.  
  111. nlTab
  112.     self nl.
  113.     self tab
  114. !
  115.  
  116. space
  117.     self nextPut: Character space
  118. !
  119.  
  120. tab
  121.     self nextPut: Character tab
  122. !!
  123.  
  124.  
  125.  
  126. !WriteStream methodsFor: 'private methods'!
  127.  
  128. initCollection: aCollection
  129.     collection _ aCollection.
  130.     ptr _ 1.
  131.     endPtr _ 0.
  132.     maxSize _ aCollection size
  133. !
  134.  
  135. moveToEnd
  136.     endPtr _ collection size.
  137.     self setToEnd
  138. !
  139.  
  140. workingSize
  141.     "Return the actual number of valid elements in the stream"
  142.     ^ptr max: endPtr
  143. !
  144.  
  145. growCollection
  146.     collection grow.
  147.     maxSize _ collection size
  148.  
  149. !!
  150.  
  151.